package com.gimi.cloud.bbp.dao.dao.page;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.gimi.cloud.bbp.dao.myMapper.MyMapper;
import com.gimi.cloud.bbp.dto.page.PageConfigDTO;
import com.gimi.cloud.bbp.entity.page.PageConfig;

@Mapper
public interface PageConfigDao extends MyMapper<PageConfig>{
	
	@Select("select * from pc_page_config where is_delete = '0' and id = #{id}")
	@Results({
		@Result(property = "id", column = "id"),
		@Result(property = "pageColumns", column = "id" , many = @Many(select = ("com.gimi.cloud.bbp.dao.dao.page.PageColumnDao.getPageColumnByPageId")))
	})
	PageConfigDTO getPageAllById(Integer id);
	
	@Select("select * from pc_page_config where is_delete = '0' and type = #{type} and ((start_time < now() and end_time > now() and status = 3 ) or status = 4) LIMIT 1")
	@Results({
		@Result(property = "id", column = "id"),
		@Result(property = "pageColumns", column = "id" , many = @Many(select = ("com.gimi.cloud.bbp.dao.dao.page.PageColumnDao.getPageColumnByPageId")))
	})
	PageConfigDTO getPageByType(Integer type);
	
	@Select("select * from pc_page_config where is_delete = '0' and id = #{id} and ((start_time < now() and end_time > now() and status = 3 ) or status = 4)")
	@Results({
		@Result(property = "id", column = "id"),
		@Result(property = "pageColumns", column = "id" , many = @Many(select = ("com.gimi.cloud.bbp.dao.dao.page.PageColumnDao.getPageColumnByPageId")))
	})
	PageConfigDTO getPageById(Integer id);
	
	@Update("update pc_page_config set is_delete = '1' where id in (${ids})")
	Long delPageById(@Param("ids") String ids);
	
	
	
}
